package buttons.control;

import buttons.view.V_DoubleSlider;
import processing.core.PVector;
import controllers.ControlManager;

public class C_DoubleSlider extends C_Button
{  
  int dragging = -1;
  float dragOffset = 0.0f;
  float startPos = 0.0f;
  PVector startRectPositions;
  
  public C_DoubleSlider(V_DoubleSlider viewButton){
    super(viewButton);
  }
  
  @Override
  public void onInteract (float mouseXLoc, float mouseYLoc, String interID)
  {
	if(enabled)
	{
	    V_DoubleSlider button = (V_DoubleSlider)vFeature;
	    int containsWhat = button.containsWhat(mouseXLoc, mouseYLoc);
	    
	    if(interID.equals(""))
	    {
	      if(containsWhat == 0) {
	        button.setColorOffsets(20, 0, 0);
	      }
	      
	      else if(containsWhat == 1) {
	        button.setColorOffsets(0, 20, 0);
	      }
	      
	      else if(containsWhat == 2) {
	        button.setColorOffsets(0, 0, 10);
	      }
	      
	      else {
	        button.setColorOffsets(0,0,0);
	      }
	      
	      // HANDLE TOOLTIP WHEN RELEASED:
	      if(containsWhat > -1) handleTooltip(mouseXLoc, mouseYLoc);
	    }
	    
	    if(interID.equals("leftDrag") || interID.equals("leftPressed")) {
	      if(dragging == -1)
	      {
	        startPos = mouseXLoc;
	        dragging = containsWhat;
	        startRectPositions = button.getRects();
	      }
	      dragOffset = mouseXLoc - startPos;
	      if(dragging == 0)
	      {
	        button.moveRect1(startRectPositions.x + dragOffset);
	        triggerEvent("moveLeftSlider");
	      }
	      else if(dragging == 1)
	      {
	        button.moveRect2(startRectPositions.y + dragOffset);
	        triggerEvent("moveRightSlider");
	      }
	      else if(dragging == 2)
	      {
	        button.moveRect1(startRectPositions.x + dragOffset);
	        button.moveRect2(startRectPositions.y + dragOffset);
	        triggerEvent("moveBothSliders");
	      }
	    }
	    else if(interID.equals("released")) {
	      dragging = -1;
	      dragOffset = 0;
	      startRectPositions = null;
	    }
	}
  }
}
